// EducationHistory.cs
// Facebook/Framework/Service
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace Facebook.Service {

    /// <summary>
    /// Represents a Facebook education history entry on the user's profile.
    /// </summary>
    public sealed class EducationHistory : FacebookEntity {

        private bool _concentrationsTransformed;

        internal EducationHistory(Hashtable educationHistoryState)
            : base(educationHistoryState) {
        }

        /// <summary>
        /// The list of named concentrations.
        /// </summary>
        public ICollection<string> Concentrations {
            get {
                if (_concentrationsTransformed == false) {
                    return TransformConcentrations();
                }
                return (ICollection<string>)this["concentrations"];
            }
        }

        /// <summary>
        /// The name of the school.
        /// </summary>
        public string Name {
            get {
                return GetState<string>("name") ?? String.Empty;
            }
        }

        /// <summary>
        /// The year of graduation.
        /// </summary>
        public string Year {
            get {
                return GetState<string>("year") ?? String.Empty;
            }
        }

        private ICollection<string> TransformConcentrations() {
            Debug.Assert(_concentrationsTransformed == false);

            ArrayList concentrationsState = (ArrayList)this["concentrations"];
            string[] concentrations = (string[])concentrationsState.ToArray(typeof(string));

            this["concentrations"] = concentrations;
            _concentrationsTransformed = true;

            return concentrations;
        }
    }
}
